package com.example.livereplay.common.validator.oauthclientdetails;

import com.example.livereplay.common.model.enity.SysOauthClientDetails;
import com.example.livereplay.exception.SysBusinessCode;
import com.example.livereplay.exception.SysBusinessException;
import com.example.livereplay.common.validator.BaseValidator;
import org.springframework.util.StringUtils;

public class SysOauthClientDetailsValidator extends BaseValidator {
    public static void insertValidate(SysOauthClientDetails sysOauthClientDetails) {
        if (!StringUtils.hasText(sysOauthClientDetails.getClientId())) {
            throw new SysBusinessException(SysBusinessCode.OAUTH_CLIENT_CLIENT_ID_EMPTY_ERROR);
        }
        if (!StringUtils.hasText(sysOauthClientDetails.getClientSecret())) {
            throw new SysBusinessException(SysBusinessCode.OAUTH_CLIENT_SECRET_EMPTY_ERROR);
        }
        if (!StringUtils.hasText(sysOauthClientDetails.getAuthorizedGrantTypes())) {
            throw new SysBusinessException(SysBusinessCode.OAUTH_CLIENT_AUTHORIZED_GRANT_TYPES_EMPTY_ERROR);
        }
        if (!StringUtils.hasText(sysOauthClientDetails.getClientName())) {
            throw new SysBusinessException(SysBusinessCode.OAUTH_CLIENT_NAME_EMPTY_ERROR);
        }
    }

    public static void updateValidate(SysOauthClientDetails sysOauthClientDetails) {
        if (!StringUtils.hasText(sysOauthClientDetails.getId())) {
            throw new SysBusinessException(SysBusinessCode.ID_EMPTY_ERROR);
        }
        if (!StringUtils.hasText(sysOauthClientDetails.getPrivateKey())) {
            throw new SysBusinessException(SysBusinessCode.PRIVATE_KEY_EMPTY_ERROR);
        }
        if (!StringUtils.hasText(sysOauthClientDetails.getPublicKey())) {
            throw new SysBusinessException(SysBusinessCode.PUBLIC_KEY_EMPTY_ERROR);
        }
        insertValidate(sysOauthClientDetails);
    }
}
